/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import entities.User;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author alessandro
 */
public class UserDAO {
    /*@PersistenceUnit(unitName="HeartsSDITeamPU")
    static EntityManagerFactory emf;
    @PersistenceContext(unitName="HeartsSDITeamPU")
    static EntityManager em;*/

    public static User findUser(String username, String password) {
        User user = null;
        try {
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("HeartsSDITeamPU");
            EntityManager em = emf.createEntityManager();
            user = (User) em.createNamedQuery("User.findByUserAndPassword").setParameter("user", username).setParameter("password", password).getResultList().get(0);
        } catch (Exception e) {
        }
        return user;

    }
}
